// 添加和编辑 大咖报告弹窗
import React, { Component } from 'react'
import { Button,Form, Input, Modal, Select,Upload ,Icon ,message,Spin,Cascader} from 'antd'
import { connect } from 'react-redux'
/* 引用接口文档路径 */
import {
    masterInfo,adoptMasterReport
  } from 'actions/materialManage'
import {getbasetypefetch} from 'actions/common'
import '../style/userControl.less'
@connect(
  (state, props) => ({
    config: state.config,
    userInfoList: state.userInfoList,
  })
)


export default class LookMasterReport extends Component {
  
    constructor (props) {
      super(props)
      this.state = {
        modalList:"",
        contentModal: true,
        buttongroup:[],
      }
    }
    componentWillMount() {
    }
    componentDidMount() {
        this.setState({
            contentModal:this.props.visible
          })
        this.showModal(this.props.id);
    }
    componentWillReceiveProps(props){
    }
    refuseFN(id){
        this.props.dispatch(getbasetypefetch(
          {"type":19},
          (respose) => {
            this.setState({
                contentModal:false
            })
            this.props.btnclose()
        }))
    }
    succuesFn(id){
        this.props.dispatch(adoptMasterReport(
          {"dataType":3,"contentId":id},
          (respose) => {
            message.success(respose.respMsg);
            this.setState({
              contentModal:false
            })
            this.props.btnclose()
        }))
      }
    deleteList(id){//查看弹窗里面的删除按钮
        Modal.confirm({
        content:"确定要删除该条信息么？",
        onOk:()=>{
            this.props.dispatch(deleteMasterReport(
            {"id":id},
            (respose) => {
                var length = this.state.list.respData.count ? this.state.list.respData.count : 0;
                if(Math.ceil(length/this.pagesize) == this.currentNumber && length%this.pagesize == 1 && this.currentNumber != 1){
                this.currentNumber = this.currentNumber - 1;
                }
                message.success(respose.respMsg);
                this.contentModalCancel();           
                this.selectList(this.currentNumber);
            }))
        },
        onCancel:()=>{
        }
        })
        
    }
    contentModalCancel(){//关闭查看弹窗
        this.setState({
          contentModal: false,
        },()=>{
          this.props.closeModel()
        })
      }
    showModal(id){//点击查看  大咖报告详情
        this.props.dispatch(masterInfo({"id":id},
          (respose) => {
            if(respose.respData.dataStatus==2){
              this.setState({
                buttongroup:[
                  <Button key="ok" type="primary"  onClick={this.succuesFn.bind(this,respose.respData.id)}>通过</Button>,
                  <Button key="cancel" type="primary"  onClick={this.refuseFN.bind(this,respose.respData.id)}>拒绝</Button>
                ]
              })
            }
            else if(respose.respData.dataStatus!=2){
              this.setState({
                buttongroup:[
                  <Button key="del" type="primary"  onClick={this.deleteList.bind(this,respose.respData.id)}>删除</Button>
                ]
              })
            }
            this.setState({
              contentModal: true,
              modalList:respose,
            })
    
        }))
      }
    render () {
        const modalList = this.state.modalList.respData ? this.state.modalList.respData :[];
        return (
            <Modal
            width={"80%"}
            visible={this.state.contentModal}
            title="报告详情"
            onCancel={this.contentModalCancel.bind(this)}
            footer={this.state.buttongroup}
          >
            <ul className="joinBlackListModal">
              <li>
                <span className="title">发布人:</span><span className="content"><span style={{marginRight:'10px'}}>{modalList.publisherName}</span>{modalList.positionName}</span>
              </li>
              <li>
                <span className="title">发布时间:</span><span className="content">{modalList.createTime}</span>
              </li>
              <li>
                <span className="title">报告类别:</span><span className="content">{modalList.typeName}</span>
              </li>
              <li>
                <span className="title">报告内容:</span><span className="content" dangerouslySetInnerHTML={{__html: modalList.detail}}></span>
              </li>
              <li>
                <span className="title">累计评论:</span><span className="content">{modalList.commentTotal}</span>
              </li>
              <li>
                <span className="title">累计被赞:</span><span className="content">{modalList.fabulousTotal}</span>
              </li>
              <li>
                <span className="title">累计阅读:</span><span className="content">{modalList.readTotal}</span>
              </li>
            </ul>
          </Modal>
        )
    }
}